package com.jason.kotlin.gank.ui.fragments

import com.jason.kotlin.gank.viewmodel.GankCategoryViewModel
import com.jason.library.common.base.BaseStateTabFragment
import com.jason.library.common.ext.observe

/**
 * @description: GankArticleTabFragment
 *
 * @author ChenBaoyang
 * @date 4/20/21 14:05
 */
class GankArticleTabFragment : BaseStateTabFragment<GankCategoryViewModel>() {


    companion object{
        fun newInstance(): GankArticleTabFragment {
            return GankArticleTabFragment()
        }
    }

    override fun bindLiveData() {
        observe(viewModel!!.categoryArticle){
            for (i in it.data!!) {
                pagerAdapter.addFragment(
                    GankArticleChildFragment.newInstance(
                        i.type
                    ), i.title)
            }
            pagerAdapter.notifyDataSetChanged()
        }
    }

    override fun onDataInit() {
        viewModel!!.loadGArticleCategories()
    }

    override fun reload() {
        onDataInit()
    }
}